/**
 * Created by DukeCrushIt on 2015/7/27.
 */
class MainTab extends eui.Component{
    public constructor(){
        super();
        this.skinName = "pet.MainTabSkin";
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.addedToStage, this);
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.removedFromStage, this);
        this.x= 0;
        this.y = 712;
    }

    private onTabTouched(evt:egret.TouchEvent){
        var tar:any = evt.currentTarget;
        SoundMgr.getInstance().playEffect(SoundMgr.BTN);
        if( tar == this.btn_home){
            SceneMgr.getInstance().switchScene(SceneMgr.SCENE_MAIN);
            setTimeout(function(){
                Model.checkGuide("home");
            },200);
        }else if( tar == this.btn_petshop){
            SceneMgr.getInstance().switchScene(SceneMgr.SCENE_TRAVEL);
            RedPointMgr.getInstance().update(RedPointMgr.TRAVE_ICON,false);
            setTimeout(function(){
                Model.checkGuide("travel");
            },200);
        }else if( tar == this.btn_shop){
            SceneMgr.getInstance().switchScene(SceneMgr.SCENE_SHOP);
            setTimeout(function(){
                Model.checkGuide("shop");
            },200);

        }else if( tar == this.btn_date){
            RedPointMgr.getInstance().update(RedPointMgr.GETOU_ICON,false);
            SceneMgr.getInstance().switchScene(SceneMgr.SCENE_GETOUT);
            setTimeout(function(){
                Model.checkGuide("petshop");
            },200);
        }else if( tar == this.img_decorate){
            SceneMgr.getInstance().switchScene(SceneMgr.SCENE_DECORATE);
            setTimeout(function(){
                Model.checkGuide("enter_dec");
            },200);
        }
    }

    private addedToStage(evt:egret.Event){
        this.btn_date.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.btn_home.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.btn_petshop.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.btn_shop.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.img_decorate.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.img_sociaty.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
    }

    private removedFromStage(evt:egret.Event){
        this.btn_date.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.btn_home.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.btn_petshop.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.btn_shop.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.img_decorate.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
        this.img_sociaty.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTabTouched, this);
    }

    public btn_home:eui.Image;
    public btn_petshop:eui.Image;
    public btn_shop:eui.Image;
    public btn_date:eui.Image;
    public img_decorate:eui.Image;
    public img_sociaty:eui.Image;

    public hint_travel:eui.Image;
    public hint_dec:eui.Image;
    public hint_getout:eui.Image;
    public hint_guild:eui.Image;
    public partAdded(name:string,instance:any){
        super.partAdded(name,instance);
        if( name == "img_home"){
            this.btn_home = instance;
        }else if( name == "img_petshop"){
            this.btn_petshop = instance;
        }else if( name == "img_shop"){
            this.btn_shop = instance;
        }else if( name == "img_date"){
            this.btn_date = instance;
        }else if( name == "img_decorate"){
            this.img_decorate = instance;
        }else if( name == "img_sociaty"){
            this.img_sociaty = instance;
        }else if( name == "hint_travel"){
            this.hint_travel = instance;
            RedPointMgr.getInstance().registerPoint(RedPointMgr.TRAVE_ICON,instance);
        }else if( name == "hint_dec"){
            this.hint_dec = instance;
            RedPointMgr.getInstance().registerPoint(RedPointMgr.DEC_ICON,instance);
        }else if( name == "hint_getout"){
            this.hint_getout = instance;
            RedPointMgr.getInstance().registerPoint(RedPointMgr.GETOU_ICON,instance);
        }else if( name == "hint_guild"){
            this.hint_guild = instance;
            RedPointMgr.getInstance().registerPoint(RedPointMgr.GUILD_ICON,instance);
        }
    }

    private static _instance:MainTab;
    public static getInstance():MainTab{
        if( MainTab._instance == null)
            MainTab._instance = new MainTab();
        return MainTab._instance;
    }
}